/**
 * All Rights Reserved , Copyright (C) 2021 , 青岛鼎信通讯股份有限公司
 * BaseFlowRoleUserController
 * 流程角色人员
 * 修改纪录
 * 2021-01-11 版本：1.0 wanghanwei 创建。
 * 
 * @version 版本：1.0
 * @author 作者：wanghanwei
 * 创建日期：2021-01-11
 */
package com.topscomm.base.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topscomm.base.controller.auto.BaseFlowRoleUserControllerAuto;
import com.topscomm.base.pojo.BaseFlowRoleUserEntity;
import com.topscomm.pub.util.StringBufferProxy;
import com.topscomm.pub.util.StringUtil;
import com.topscomm.pub.vo.ResponseResult;

/**
 * @author: wanghanwei
 * @date: 2021-01-11
 * @description:流程角色人员Controller
 * @modify:
 */
@RestController
@RequestMapping("base/flowRoleUser")
public class BaseFlowRoleUserController extends BaseFlowRoleUserControllerAuto implements IBaseFlowRoleUserController {
	/**
	 * @author: wanghanwei
	 * @date: 2021-01-11
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	protected String spellListSql(Map<String, Object> paraMap) {
		StringBufferProxy sql = new StringBufferProxy();
		sql.appendSingle(" 1=1 ");
		if (paraMap.containsKey("qry_name")) {
			String value = paraMap.get("qry_name").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and name like '%{0}%' ", value);
		}
		if (paraMap.containsKey("qry_code")) {
			String value = paraMap.get("qry_code").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and code = '{0}' ", value);
		}
		if (paraMap.containsKey("qry_roleid")) {
			String value = paraMap.get("qry_roleid").toString();
			if (!StringUtil.isEmpty(value))
				sql.appendSingle(" and roleid = '{0}' ", value);
		}
		return sql.toString();
	}

	/**
	 * @author: wanghanwei
	 * @date: 2021-01-11
	 * @param paraMap
	 * @return
	 * @description:转换出查询SQL语句
	 * @modify:
	 */
	@Override
	@GetMapping(value = "/refList")
	public ResponseResult<Object> refList(@RequestParam(required = false) Map<String, Object> paraMap) {
		return super.refList(paraMap);
	}

	/**
	 * @description:批量保存
	 * @auther: wanghanwei
	 * @date: 2021年1月12日下午2:25:21
	 * @modify:
	 */
	@PostMapping(value = "/batchSave")
	public ResponseResult<Object> batchSave(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			return this.service.saveBatch(paraMap);
		} catch (Exception e) {
			return handleControllerException(e);
		}
	}

	/**
	 * @description:更新
	 * @auther: wanghanwei
	 * @date: 2021年1月12日下午2:25:21
	 * @modify:
	 */
	@PostMapping(value = "/scopedeptUpdate")
	public ResponseResult<Object> scopedeptUpdate(@RequestBody(required = false) Map<String, Object> paraMap) {
		try {
			return this.service.scopedeptUpdate(paraMap);
		} catch (Exception e) {
			return handleControllerException(e);
		}
	}

	@Override
	protected void afterLoad(Map<String, Object> paraMap) {
		super.afterLoad(paraMap);
		if (null != paraMap.get("scopedept")) {
			String scopedeptString = StringUtils.strip(paraMap.get("scopedept").toString().replace("\"", ""), "[]");
			List<String> scopedeptList = Arrays.asList(scopedeptString.split(","));
			paraMap.put("dispscopedept", scopedeptList);
		}
	}

	/**
	 * @description:修复历史数据
	 * @author: zhanglongfei
	 * @date: 2021年3月5日下午2:23:06
	 * @modify:
	 */
	@GetMapping(value = "/testFixedData")
	public void testFixedData() {
		try {
			List<BaseFlowRoleUserEntity> list = this.service.queryByWhere("scopetype='1'");
			for (BaseFlowRoleUserEntity baseFlowRoleUserEntity : list) {
				if (!StringUtil.isEmpty(baseFlowRoleUserEntity.getScopedept())) {
					String aString = StringUtils.strip(baseFlowRoleUserEntity.getScopedept().replace("\"", ""), "[]");
					this.service.updateExecute("update baseflowroleuser set scopedept='" + aString + "' where id=" + baseFlowRoleUserEntity.getId());
				}
			}
			System.out.println("成功");
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
}
